package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理", description = "频道管理的接口信息", tags = "channel")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService adChannelService;


    /**
     * 频道列表查询
     *
     * @param channelDto
     * @return
     */
    @Override
    @PostMapping("/list")
    @ApiOperation(value = "查询频道列表", notes = "根据频道名称模糊查询频道列表")
    @ApiImplicitParam(name = "channelDto", type = "ChannelDto", value = "频道名称")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto) {
        return adChannelService.findByNameAndPage(channelDto);
    }

    /**
     * 频道保存
     *
     * @param adChannel
     * @return
     */
    @Override
    @PostMapping("/save")
    @ApiOperation(value = "频道添加", notes = "新增频道信息")
    @ApiImplicitParam(name = "adChannel", type = "AdChannel", value = "频道对象")
    public ResponseResult save(@RequestBody AdChannel adChannel) {
        return adChannelService.saveChannel(adChannel);
    }

    /**
     * 修改频道
     *
     * @param adChannel
     * @return
     */
    @Override
    @PostMapping("/update")
    @ApiOperation(value = "频道修改", notes = "修改频道信息")
    @ApiImplicitParam(name = "adChannel", type = "AdChannel", value = "频道对象")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.updateChannel(adChannel);
    }

    /**
     * 删除频道
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/del/{id}")
    @ApiOperation(value = "频道删除", notes = "根据频道id删除频道信息")
    @ApiImplicitParam(name = "id", type = "Integer", value = "频道id")
    public ResponseResult deleteById(@PathVariable Integer id) {
        return adChannelService.deleteById(id);
    }


    /**
     * 查询频道列表，提供给文章列表下拉框使用
     * @return
     */

    @GetMapping("/channels")
    @Override
    public ResponseResult channels(){
        return ResponseResult.okResult(adChannelService.list());
    }


}
